/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { HttpSrv } from 'lfun-bg-comp';
import { ImportParams, PageParams, PageResult, Result } from '..';

export interface InstitutionParams {
  social_credit_code?: string;
  institution_name?: string;
  institution_org_type?: string;
  borough?: string;
  block?: string;
  institution_category: 'institution' | 'administration';
}
export interface InstitutionRes {
  institution_name: string;
  institution_category: 'institution' | 'administration';
  social_credit_codeleg_repr_name: string;
  status: string;
  create_date: string;
}

// 分页查询
export const searchInstitution = (params: InstitutionParams & PageParams): Result<PageResult<InstitutionRes>> => {
  return HttpSrv().get(`/school/v1/institution/page`, {
    params: { ...params },
  });
};

// 删除
export const deleteInstitution = (id: any): Result<any> => {
  return HttpSrv().delete(`/school/v1/institution/${id}`);
};
export interface CloseInstitution {
  institution_id: string;
  action_reason: string;
  related_license_upload: string[];
}
// 关闭
export const closeInstitution = (params: CloseInstitution) =>
  HttpSrv().patch(`/school/v1/institution/close`, {}, { params: { ...params } });

export interface InstitutionKeyInfo {
  institution_name?: string;
  institution_code?: string;
  block?: string;
  borough?: string;
  membership_no?: string;
  institution_category: 'institution' | 'administration';
}
// 新增
export const createInstitution = (params: InstitutionKeyInfo) => HttpSrv().post('/school/v1/institution/', params);
export interface InstitutionInfo {
  institution_name?: string;
  institution_en_name?: string;
  institution_category?: string;
  institution_type?: string;
  fax_number?: string;
  email?: string;
  contact_number?: string;
  area_code?: string;
  institution_code?: string;
  create_date?: string;
  leg_repr_name?: string;
  party_leader_name?: string;
  party_leader_position?: string;
  adm_leader_name?: string;
  adm_leader_position?: string;
  membership_no?: string;
  sy_zones?: string;
  social_credit_code?: string;
  postal_code?: string;
  detailed_address?: string;
  related_license_upload?: string;
  long?: string;
  lat?: string;
  urban_rural_nature?: string;
  location_economic_attribute?: string;
  leg_repr_certificatenumber?: string;
  is_entity?: string;
  website_url?: string;
  status?: string;
  membership_category?: string;
}
// // 修改
export const updateInstitution = (info: InstitutionInfo) => HttpSrv().patch(`/school/v1/institution/baseinfo`, info);
// 开办
export const openInstitution = (institution_id, info: InstitutionInfo) =>
  HttpSrv().patch(`/school/v1/institution/open?institution_id=${institution_id}`, info);

// 查询单个
export const getInstitution = institution_id =>
  HttpSrv().get(`/school/v1/institution/`, { params: { institution_id } });
// 关键信息修改
export const updateInstitutionKeyInfo = (info: InstitutionKeyInfo) =>
  HttpSrv().put(`/school/v1/institution/keyinfo`, info);

export const institutionCloseAudit = (process_instance_id: any, remark: string, is_approve: boolean) =>
  HttpSrv().patch(`/school/v1/institution/close-audit`, {
    process_instance_id,
    remark,
    transaction_audit_action: is_approve ? 'pass' : 'refuse',
  });
export const institutionKeyinfoAudit = (process_instance_id: any, remark: string, is_approve: boolean) =>
  HttpSrv().patch(`/school/v1/institution/keyinfo-audit`, {
    process_instance_id,
    remark,
    transaction_audit_action: is_approve ? 'pass' : 'refuse',
  });
export const institutionOpenAudit = (process_instance_id: any, remark: string, is_approve: boolean) =>
  HttpSrv().patch(`/school/v1/institution/open-audit`, {
    process_instance_id,
    remark,
    transaction_audit_action: is_approve ? 'pass' : 'refuse',
  });

export const importInstitution = (params: ImportParams) =>
  HttpSrv().post(`/school/v1/institution/institution-import`, params);

// 分页查询
export const searchInstitutionAudit = (params: InstitutionParams & PageParams): Result<PageResult<InstitutionRes>> => {
  return HttpSrv().get(`/school/v1/institution/institution-audit`, {
    params: { ...params },
  });
};

export const exportStuInfo = (params: any): Promise<any> =>
  HttpSrv().post('/school/v1/institution/institution-export?status=draft&institution_category=institution', {
    ...params,
  });
